package com.db.williamchart.renderer.executor;

import com.db.williamchart.data.AxisType;
import com.db.williamchart.data.Paddings;

public class MeasureHorizontalBarChartPaddings {

    public Paddings invoke(AxisType axisType, Float labelsHeight, Float xLastLabelWidth, Float yLongestLabelWidth, Float labelsPaddingToInnerChart) {
        return measurePaddingsX(axisType, labelsHeight, xLastLabelWidth, labelsPaddingToInnerChart)
                .mergeWith(
                        measurePaddingsY(axisType, yLongestLabelWidth, labelsPaddingToInnerChart)
                );
    }

    private Paddings measurePaddingsX(
            AxisType axisType,
            Float labelsHeight,
            Float xLastLabelWidth,
            Float labelsPaddingToInnerChart
    ) {

        if (!axisType.shouldDisplayAxisX()) {
            return new Paddings(0F, 0F, 0F, 0F);
        }
        return new Paddings(
                0F,
                0F,
                xLastLabelWidth / 2,
                labelsHeight + labelsPaddingToInnerChart
        );
    }

    private Paddings measurePaddingsY(
            AxisType axisType,
            Float yLongestLabelWidth,
            Float labelsPaddingToInnerChart
    ) {

        if (!axisType.shouldDisplayAxisY()) {
            return new Paddings(0F, 0F, 0F, 0F);
        }
        return new Paddings(
                yLongestLabelWidth + labelsPaddingToInnerChart,
                0f,
                0F,
                0f
        );
    }
}
